﻿using System;
using Model.Manager;
using Model.Manager.DataBase;
using Model.Platform.PhysicalData;


namespace BML.Infrastructure.Logger
{
    /// <summary>
    ///     操作日志
    /// </summary>
    public static class OperatorLogger
    {
        #region 自行封装异常，异常记录在本地文件日志（可配置）

        #endregion

        #region DB

        /// <summary>
        /// </summary>
        /// <param name="userIdentityId">用户主键ID</param>
        /// <param name="behaviorTypes">行为类型</param>
        /// <param name="behaviorDetails">行为细节</param>
        /// <param name="behaviorOccurrenceTime">行为发生时间</param>
        /// <param name="consequenceTypes">结果类型</param>
        /// <param name="consequenceDetails">结果细节</param>
        /// <param name="consequenceOccurrenceTime">结果发生时间</param>
        /// <param name="otherEventId"></param>
        public static void LogDb(Guid userIdentityId, int behaviorTypes, string behaviorDetails,
                                 DateTime behaviorOccurrenceTime, int consequenceTypes, string consequenceDetails,
                                 DateTime consequenceOccurrenceTime, Guid otherEventId)
        {
            using (IDbContext db = ContextFactory.GetPlatformConnect())
            {
                db.GetOperator<OperationsLog>().Create(new OperationsLog
                    {
                        Id = Guid.NewGuid(),
                        UserIdentityId = userIdentityId,
                        BehaviorTypes = behaviorTypes,
                        BehaviorDetails = behaviorDetails,
                        BehaviorOccurrenceTime =
                            behaviorOccurrenceTime,
                        ConsequenceTypes = consequenceTypes,
                        ConsequenceDetails = consequenceDetails,
                        ConsequenceOccurrenceTime = consequenceOccurrenceTime,
                        OtherEventId = otherEventId
                    });
                db.SaveAllChange();
            }

        }

        /**/

        #endregion

        #region 本地文档XML输出

        #endregion
    }
}